let version, vGet
if (localStorage.getItem('version')) {
  version = localStorage.getItem('version')
}
let req = new XMLHttpRequest()
req.open('get', './version.json')
req.send(null)
req.onload = function () {
  if (req.status == 200) {
    vGet = JSON.parse(req.responseText)
    if (vGet) {
      //判断之前是否看过新特性
      if (localStorage.version == vGet[0].id) {
        return
      }
      localStorage.version = vGet[0].id
      //前端页面排版
      let v_box = document.createElement('div')
      v_box.className = 'box'
      let h1 = document.createElement('h1')
      h1.style = 'text-align: center; margin: 20px 0 0 0'
      h1.innerText = '版本更新' + vGet[0].name
      v_box.appendChild(h1)
      let hr = document.createElement('hr')
      hr.style = 'width: 90%'
      v_box.appendChild(hr)
      let v_items = document.createElement('div')
      v_items.id = 'v_items'
      for (let item of vGet) {
        let v_name = document.createElement('h2')
        v_name.className = 'v_name'
        v_name.innerText = '版本' + item.name
        let v_time = document.createElement('div')
        v_time.className = 'v_time'
        v_time.innerText = item.time
        let v_title = document.createElement('div')
        v_title.className = 'v_title'
        v_title.appendChild(v_name)
        v_title.appendChild(v_time)
        let v_contents = document.createElement('ul')
        v_contents.className = 'v_contents'
        for (let cont of item.contents) {
          let v_content = document.createElement('li')
          v_content.innerText = cont
          v_contents.appendChild(v_content)
        }
        let v_item = document.createElement('div')
        v_item.className = 'v_item'
        v_item.appendChild(v_title)
        v_item.appendChild(v_contents)
        v_items.appendChild(v_item)
      }
      v_box.appendChild(v_items)
      let v_dom = document.createElement('div')
      v_dom.id = 'version'
      v_dom.appendChild(v_box)
      document.body.appendChild(v_dom)
      let close = document.createElement('div')
      close.className = 'close'
      close.innerText = '×'
      close.onclick = function () {
        v_dom.hidden = true
      }
      v_box.appendChild(close)
      if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
        console.log('移动端')
        v_box.style = 'width:95%'
      }
      //滚动到顶部
      v_items.scrollTop = 0
    }
  }
}
